//
//  CZMainTabbar.swift
//  weibo123456
//
//  Created by 露露 on 16/6/6.
//  Copyright © 2016年 lulu. All rights reserved.
//

import UIKit

class CZMainTabbar: UITabBar {
  //表示5个字控件
  private  let count = 5
    
    
   override func layoutSubviews() {
    
//   计算uitabb arbutton的宽度
    let width = self.bounds.width / CGFloat(count)
//   计算最边上的frame
    let frame = CGRect(x: 0, y: 0, width: width, height: self.bounds.height)
    
//   便利自控件
    var index = 0


    for view in self.subviews {
        if view is UIControl{
          
            
            view.frame = CGRectOffset(frame, CGFloat(index) * width, 0)
        
           index += index == 1 ? 2 : 1
        
        }
       }
      // 设置加号按钮的frame
    composeButton.frame = CGRectOffset(frame, 2.0 * width, 0)
    
     }
  
//添加按钮
    lazy var composeButton:UIButton = {
   let button = UIButton()
//       设置图片
        button.setBackgroundImage(UIImage(named:"tabbar_compose_button"), forState: UIControlState.Normal)
           button.setBackgroundImage(UIImage(named:"tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
  // 设置按钮图片    
        
        button.setImage(UIImage(named :"tabbar_compose_icon_add"), forState: UIControlState.Normal)
        
        button.setImage(UIImage(named :"tabbar_compose_icon_add"), forState: UIControlState.Highlighted)

//        添加
        self.addSubview(button)
        return button
    
    }()



}
   

